<?php
require_once('../smarty/Smarty.class.php') ;
require_once('../common/http_helper.php');
session_start();
// echo var_export($_SESSION):
// exit();
if (isset($_SESSION[realpath("..") . 'views']) && $_SESSION[realpath("..") . 'views'] == true) {
} else {
    $_SESSION[realpath("..") . 'views'] = false;
    echo "<script>window.location='../wall/login.php?url=" . $_SERVER['PHP_SELF'] . "';</script>";
    die;
}
// echo getparams('style');
$style=getparams('style');
if (isset($style) && !empty($style)) {
    $style = $style;
} else {
    $style = "custom";
}
include('db.php');
// exit('系统更新测试中。。。');

$conf = $wall_config->find();
// exit('系统更新测试中。。。');
/**
 *
 * 以下为获取页面插件
 *
 * qdq_switch    tinyint(1) [0]
 * cj_switch    tinyint(1) [0]
 * ddp_switch    tinyint(1) [0]
 * weibo_switch    tinyint(1) [0]
 * weixin_switch
 * */
$plugsc = new M('plugs');
$plugsa = $plugsc->select('switch =1');
foreach ($plugsa as $plugin) {
    if ($plugin['name'] == 'cj') {
        if (@file_exists("cjg_plug/cjg_html.php")) {
            $plugs['cjg'] = 1;
            $plugs['cj'] = 0;
        }
    }
    if (@file_exists($plugin['name'] . "_plug/" . $plugin['name'] . "_html.php")) {
        $plugs[$plugin['name']] = 1;
    }
}
if (file_exists("../api/weixin.php") && $conf['weixin_switch']) {
    $weixin = 1;
    $flag = new M('weixin_config');
    $weixinconf = $flag->find();
    $weixin_name = $weixinconf['nickname'];
    $dianplu_wxh = $weixinconf['dianplu_wxh'];
} else {
    $weixin = 0;
}
if (file_exists("../api/weibo.php") && $conf['weibo_switch']) {
    $weibo = 1;
    $flag = new M('weibo_config');
    $weiboconf = $flag->find('id=1');
} else {
    $weibo = 0;
}
$smarty = new Smarty;
// $smarty->debugging = true;
$smarty->caching = false;
// echo dirname(__FILE__);
$apppath=str_replace(DIRECTORY_SEPARATOR.'wall', '', dirname(__FILE__));
$smarty->compile_dir = $apppath.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'templates_c'.DIRECTORY_SEPARATOR;
// $smarty->cache_lifetime = 120;
$smarty->assign('config',$xuanzezu);
$smarty->assign('plugs',$plugs);
include 'style.php';
$smarty->assign('styles',$styles);
// $html='';
// foreach ($plugs as $k => $v) {
//     if ($plugs[$k] == 1) {
//         $html.=file_get_contents($k . '_plug/' . $k . '_html.php');
//     }
// }
if(isset($plugs['vote']) && $plugs['vote']==1){
    $voteplug = $plugsc->find('name="vote"');
    $smarty->assign('voteplug',$voteplug);
}
 

$smarty->assign('weibo',$weibo);
$smarty->assign('weixin',$weixin);
// $smarty->assign('plugs_html',$html);
$smarty->assign('dianplu_wxh',$dianplu_wxh);
$smarty->assign('weiboconf',$weiboconf);
$smarty->assign('weixinconf',$weixinconf);
$smarty->assign('style',$style);
// $wall_num_m=new M('wall_num');
// $row=$wall_num_m->findarray('1','num');
// $lastid = $row["num"] -5;
// if($lastid < 0){
//     $lastid = 0;
// }
$smarty->assign('lastid',getlastid());

$smarty->display('themes/'.$style.'/index.html');
//获取最后一条信息的id
function getlastid(){
    $wall_m=new M('wall');
    $row=$wall_m->find(' ret=1 order by id desc limit 1','id');
    if(isset($row['id'])){
        return intval($row['id']);
    }else{
        return 0;
    }
}
?>
